package com.qf.android.huihui.view.activity;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.qf.android.huihui.R;
import com.qf.android.huihui.adapter.information.DetilListItemAdapter;
import com.qf.android.huihui.bean.DetailListItemBean;
import com.qf.android.huihui.presenter.DetailListItemPresenter;
import com.qf.android.huihui.view.fragment.impl.IDetailListItemView;

public class DetailListItemActivity extends AppCompatActivity implements IDetailListItemView {
    private TextView title, time, content;
    private ListView detail_lv;
    private DetailListItemPresenter presenter;
    private DetilListItemAdapter adapter;

    private int id;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail_list_item);
        initWindow();
        init();
        Intent intent = getIntent();

        id = intent.getIntExtra("id", 0);
        Toast.makeText(this, id + "", Toast.LENGTH_SHORT).show();
    }

    private void initWindow() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }
    }

    private void init() {

        detail_lv = (ListView) findViewById(R.id.detail_item_lv);
        View view = LayoutInflater.from(this).inflate(R.layout.detail_item_head, null);
        title = (TextView) view.findViewById(R.id.detail_item_title);
        time = (TextView) view.findViewById(R.id.detail_item_time);
        content = (TextView) view.findViewById(R.id.detail_item_content);
        ImageView empty = new ImageView(this);
        empty.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        empty.setImageResource(R.drawable.ic_default_img);
        detail_lv.addHeaderView(view);
        presenter = new DetailListItemPresenter(this);
        presenter.getData(id);
    }

    //消息点击事件
    public void newsClick(View view) {
        Toast.makeText(this, "这是消息提示", Toast.LENGTH_SHORT).show();
    }

    //返回点击事件
    public void backClick(View view) {
        finish();
    }

    @Override
    public void setDate(DetailListItemBean bean) {
        title.setText(bean.getData().getTitle());
        time.setText("惠惠网·" + bean.getData().getPubtime().substring(0, 10));
        content.setText(bean.getData().getIntro());
        adapter = new DetilListItemAdapter(bean, this);
        detail_lv.setAdapter(adapter);
        adapter.notifyDataSetChanged();
    }
}
